package lp.xian.materials.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lp.xian.materials.domain.RequisitionTable;
import lp.xian.materials.service.IRequisitionTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 请购单数据Controller
 *
 * @author ruoyi
 * @date 2023-08-05
 */
@RestController
@RequestMapping("/table/table")
public class RequisitionTableController extends BaseController
{
    @Autowired
    private IRequisitionTableService requisitionTableService;


    /**
     * 查询请购单数据列表
     */
    @PreAuthorize("@ss.hasPermi('table:table:list')")
    @GetMapping("/list")
    public TableDataInfo list(RequisitionTable requisitionTable)
    {
        startPage();
        List<RequisitionTable> list = requisitionTableService.selectRequisitionTableList(requisitionTable);
        return getDataTable(list);
    }

    /**
     * 导出请购单数据列表
     */
    @PreAuthorize("@ss.hasPermi('table:table:export')")
    @Log(title = "请购单数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RequisitionTable requisitionTable)
    {
        List<RequisitionTable> list = requisitionTableService.selectRequisitionTableList(requisitionTable);
        ExcelUtil<RequisitionTable> util = new ExcelUtil<RequisitionTable>(RequisitionTable.class);
        util.exportExcel(response, list, "请购单数据数据");
    }

    /**
     * 获取请购单数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('table:table:query')")
    @GetMapping(value = "/{requisitionTableId}")
    public AjaxResult getInfo(@PathVariable("requisitionTableId") Integer requisitionTableId)
    {
        return success(requisitionTableService.selectRequisitionTableByRequisitionTableId(requisitionTableId));
    }

    /**
     * 根据请购单查询请购单数据列表
     */
 /*   @PreAuthorize("@ss.hasPermi('table:table:requisionI')")
    @GetMapping(value = "/{requisitionId}")
    public AjaxResult getRequisitionId(@PathVariable("requisitionId") Integer requisitionId)
    {
        return success(requisitionTableService.selectRequisitionTableByRequisitionId(requisitionId));
    }*/

    /**
     * 新增请购单数据
     */
    @PreAuthorize("@ss.hasPermi('table:table:add')")
    @Log(title = "请购单数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RequisitionTable requisitionTable)
    {
        return toAjax(requisitionTableService.insertRequisitionTable(requisitionTable));
    }

    /**
     * 修改请购单数据
     */
    @PreAuthorize("@ss.hasPermi('table:table:edit')")
    @Log(title = "请购单数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RequisitionTable requisitionTable)
    {
        return toAjax(requisitionTableService.updateRequisitionTable(requisitionTable));
    }

    /**
     * 删除请购单数据
     */
    @PreAuthorize("@ss.hasPermi('table:table:remove')")
    @Log(title = "请购单数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{requisitionTableIds}")
    public AjaxResult remove(@PathVariable Integer[] requisitionTableIds)
    {
        return toAjax(requisitionTableService.deleteRequisitionTableByRequisitionTableIds(requisitionTableIds));
    }
}
